<template>
  <div class="app-container home bg-grey">
    <!-- <TencentSpeech @tencent-speech-resultText=""/> -->

    <!-- 横幅滚动区域 -->
    <div class="banner-container">
      <el-carousel :height="bannerHeight + 'px'" indicator-position="outside" arrow="always">
        <el-carousel-item v-for="(item, index) in bannerList" :key="index">
          <img :src="baseApi+item" @load="calculateBannerHeight" />
        </el-carousel-item>
      </el-carousel>
    </div>

    <!-- 第一屏内容 - AI销售助手介绍 -->
    <div v-if="text" class="screen-section first-screen bg-fff bor-r-10 p20 mb20 animated-section">
      <div class="section-header">
        <h2 class="section-title">{{ text.title }}</h2>
        <div class="title-underline"></div>
      </div>
      <!-- 这里增加一个大按钮提醒用户去体验,点击后跳转到/app -->
      <div class="experience-button-container">
        <el-button type="primary" v-if="token" class="big-experience-button" @click="viewDemo">
          立即体验
        </el-button>
        <el-button type="primary" v-else class="big-experience-button" @click="startAIAssistant">
          登录账号
        </el-button>

      </div>
      <div class="ai-intro-content">
        <div class="intro-text fade-in-left">
          <p class="intro-paragraph">{{ text.about }}</p>
          <ul class="feature-list" v-if="text.desc">
            <li v-for="(info, index) in text.desc" :key="index" class="fade-in-up"
              :style="{ animationDelay: (index * 0.1) + 's' }">
              <i class="el-icon-check"></i>
              {{ info }}
            </li>
          </ul>
        </div>
        <div class="ai-avatar fade-in-right">
          <div class="avatar-circle pulse-animation">
            <i class="el-icon-headset"></i>
          </div>
          <div class="floating-elements">
            <span class="floating-element" style="top: 10%; left: 20%"></span>
            <span class="floating-element" style="top: 70%; left: 80%"></span>
            <span class="floating-element" style="top: 40%; left: 90%"></span>
          </div>
        </div>
      </div>
    </div>

    <!-- 第二屏内容 - 功能展示 -->
    <div v-if="features" class="screen-section second-screen bg-fff bor-r-10 p20 mb20 animated-section">
      <div class="section-header">
        <h2 class="section-title">核心功能</h2>
        <div class="title-underline"></div>
        <p class="section-subtitle">全方位助力您的销售业务提升</p>
      </div>
      <div class="features-grid">
        <div class="feature-card" v-for="(feature, index) in features" :key="index" :class="'fade-in-up'"
          :style="{ animationDelay: (index * 0.1) + 's' }">
          <div class="feature-icon gradient-border">
            <i :class="feature.icon"></i>
          </div>
          <h3>{{ feature.title }}</h3>
          <p>{{ feature.description }}</p>
        </div>
      </div>

    </div>

  </div>
</template>

<script>
import { mapGetters } from "vuex";
import { getConfigKey } from '@/api/system/config'
import Cookies from "js-cookie";


export default {
  name: "Index",
  computed: {
    ...mapGetters(["token"]),
  },
  data() {
    return {
      bannerHeight: 300,
      baseApi: process.env.VUE_APP_BASE_API,
      // 版本号
      version: "1.3.1",
      bannerList: [],
      features: [],
      text: {},
    };
  },
  mounted() {

    this.calculateBannerHeight();
    window.addEventListener('resize', this.calculateBannerHeight);
    this.initAnimations();
    // console.log('window.recorder', this.token)
  },
  created() {
    // 获取配置信息
    getConfigKey('sys.index.banner').then(response => {
      console.log("this.banner", response.msg)
      this.bannerList = response.msg ? JSON.parse(response.msg) : {}
    });
    getConfigKey('sys.index.text').then(response => {
      this.text = response.msg ? JSON.parse(response.msg) : {}
    });
    getConfigKey('sys.index.model').then(response => {
      this.features = response.msg ? JSON.parse(response.msg) : {}
    });


  },
  beforeDestroy() {
    window.removeEventListener('resize', this.calculateBannerHeight);
  },
  methods: {
    calculateBannerHeight() {
      // 根据图片实际高度调整轮播图高度
      this.$nextTick(() => {
        const img = document.querySelector('.banner-container img');
        if (img) {
          this.bannerHeight = img.offsetHeight || 200;
        }
      });
    },
    startAIAssistant() {
      const key = Cookies.get("lastTenantKey");
      if(key){
        this.$router.push('/s/login?key='+key);
      }else{
        this.$router.push('/s/login');
      }
      // this.$message.success('启动AI销售助手');
    },
    viewDemo() {
      this.$router.push('/app');
      // this.$message.info('查看功能演示');
    },
    initAnimations() {
      // 初始化动画观察器
      const observerOptions = {
        root: null,
        rootMargin: '0px',
        threshold: 0.1
      };

      const observer = new IntersectionObserver((entries) => {
        entries.forEach(entry => {
          if (entry.isIntersecting) {
            entry.target.classList.add('animated');
          }
        });
      }, observerOptions);

      document.querySelectorAll('.animated-section').forEach(section => {
        observer.observe(section);
      });
    }
  }
};
</script>

<style scoped lang="scss">
.app-container.home {
  padding: 0;
  max-width: 1200px;
  margin: 0 auto;
}

.banner-container {
  margin-bottom: 30px;
  overflow: hidden;

  ::v-deep .el-carousel__container {
    border-radius: 15px;
  }

  img {
    width: 100%;
    display: block;
  }

  ::v-deep .el-carousel__indicator--horizontal {
    padding: 0;
  }

  ::v-deep .el-carousel__indicators {
    bottom: 10px;
  }

  ::v-deep .el-carousel__arrow {
    background: rgba(255, 255, 255, 0.5);
    color: rgb(235, 135, 162);
    border-radius: 50%;
    width: 40px;
    height: 40px;

    &:hover {
      background: rgba(235, 135, 162, 0.5);
      color: white;
    }
  }
}

.screen-section {
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.08);
  border-radius: 15px;
  overflow: hidden;
  position: relative;
  padding: 40px;
  margin-bottom: 40px;
  background: linear-gradient(145deg, #ffffff, #f8f9fa);
  border: none;

  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #409EFF, #66b1ff);
  }
}

.section-header {
  text-align: center;
  margin-bottom: 40px;
}

.section-title {
  color: #2c3e50;
  font-size: 32px;
  font-weight: 600;
  margin-bottom: 15px;
  position: relative;
  display: inline-block;
}

.title-underline {
  width: 60px;
  height: 4px;
  background: linear-gradient(90deg, #409EFF, #66b1ff);
  margin: 10px auto;
  border-radius: 2px;
}

.section-subtitle {
  color: #7f8c8d;
  font-size: 18px;
  max-width: 600px;
  margin: 15px auto 0;
}

.first-screen {
  .experience-button-container {
    text-align: center;
    margin-bottom: 30px;

    .big-experience-button {
      padding: 20px 50px;
      font-size: 20px;
      border-radius: 50px;
      background: linear-gradient(90deg, #409EFF, #66b1ff);
      border: none;
      box-shadow: 0 8px 25px rgba(64, 158, 255, 0.4);
      transition: all 0.3s ease;

      &:hover {
        transform: translateY(-3px);
        box-shadow: 0 12px 30px rgba(64, 158, 255, 0.6);
        background: linear-gradient(90deg, #66b1ff, #409EFF);
      }
    }
  }

  .ai-intro-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 40px;

    .intro-text {
      flex: 1;

      .intro-paragraph {
        font-size: 20px;
        color: #34495e;
        line-height: 1.8;
        margin-bottom: 30px;
        font-weight: 300;
      }

      .feature-list {
        list-style: none;
        padding: 0;
        margin-bottom: 30px;

        li {
          padding: 12px 0;
          padding-left: 35px;
          position: relative;
          color: #2c3e50;
          font-size: 18px;
          font-weight: 300;

          i {
            color: #409EFF;
            position: absolute;
            left: 0;
            top: 12px;
            font-weight: bold;
            font-size: 20px;
          }
        }
      }
    }

    .ai-avatar {
      flex: 0 0 250px;
      text-align: center;
      position: relative;

      .avatar-circle {
        width: 180px;
        height: 180px;
        border-radius: 50%;
        background: linear-gradient(135deg, #409EFF, #66b1ff);
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0 auto;
        box-shadow: 0 10px 30px rgba(64, 158, 255, 0.4);
        position: relative;
        z-index: 2;

        i {
          font-size: 70px;
          color: white;
        }
      }

      .floating-elements {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;

        .floating-element {
          position: absolute;
          width: 20px;
          height: 20px;
          border-radius: 50%;
          background: rgba(64, 158, 255, 0.2);
          animation: float 6s infinite ease-in-out;

          &:nth-child(2) {
            animation-delay: 1s;
            width: 15px;
            height: 15px;
          }

          &:nth-child(3) {
            animation-delay: 2s;
            width: 10px;
            height: 10px;
          }
        }
      }
    }
  }
}

.second-screen {
  .features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 30px;
    margin-bottom: 50px;
  }

  .feature-card {
    text-align: center;
    padding: 40px 25px;
    border-radius: 15px;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    background: white;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    position: relative;
    overflow: hidden;

    &:hover {
      transform: translateY(-10px);
      box-shadow: 0 15px 30px rgba(64, 158, 255, 0.2);

      .feature-icon {
        transform: scale(1.1);
        box-shadow: 0 8px 25px rgba(64, 158, 255, 0.3);
      }
    }

    .feature-icon {
      width: 90px;
      height: 90px;
      margin: 0 auto 25px;
      background: linear-gradient(135deg, #ecf5ff, #d9ecff);
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: all 0.3s ease;
      box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);

      i {
        font-size: 40px;
        color: #409EFF;
      }
    }

    h3 {
      font-size: 22px;
      color: #2c3e50;
      margin-bottom: 20px;
      font-weight: 600;
    }

    p {
      color: #7f8c8d;
      line-height: 1.7;
      font-size: 16px;
    }
  }

  .action-section {
    text-align: center;
    padding: 30px 0;

    .el-button {
      margin: 0 15px;
      padding: 18px 35px;
      font-size: 18px;
      border-radius: 30px;
      border: none;
      box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
      transition: all 0.3s ease;

      &:hover {
        transform: translateY(-3px);
        box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
      }
    }
  }
}

.gradient-button {
  background: linear-gradient(90deg, #409EFF, #66b1ff);
  border: none;
  color: white;

  &:hover {
    background: linear-gradient(90deg, #66b1ff, #409EFF);
    color: white;
  }
}

/* 动画相关样式 */
.animated-section {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 0.6s ease, transform 0.6s ease;

  &.animated {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in-left {
  animation: fadeInLeft 0.8s ease forwards;
  opacity: 0;
}

.fade-in-right {
  animation: fadeInRight 0.8s ease forwards;
  opacity: 0;
}

.fade-in-up {
  opacity: 0;
  animation: fadeInUp 0.6s ease forwards;
}

.pulse-animation {
  animation: pulse 2s infinite;
}

@keyframes fadeInLeft {
  from {
    opacity: 0;
    transform: translateX(-30px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes fadeInRight {
  from {
    opacity: 0;
    transform: translateX(30px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(64, 158, 255, 0.6);
  }

  70% {
    box-shadow: 0 0 0 15px rgba(64, 158, 255, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(64, 158, 255, 0);
  }
}

@keyframes float {
  0% {
    transform: translateY(0) rotate(0deg);
  }

  50% {
    transform: translateY(-20px) rotate(10deg);
  }

  100% {
    transform: translateY(0) rotate(0deg);
  }
}

@media (max-width: 992px) {
  .screen-section {
    padding: 30px 20px;
  }

  .section-title {
    font-size: 28px;
  }
}

@media (max-width: 768px) {
  .first-screen .ai-intro-content {
    flex-direction: column;
    text-align: center;

    .intro-text {
      .feature-list {
        text-align: left;
        display: inline-block;
      }
    }

    .ai-avatar {
      flex: none;
      margin-top: 30px;
    }
  }

  .second-screen .features-grid {
    grid-template-columns: 1fr;
  }

  .action-section .el-button {
    display: block;
    margin: 10px auto;
    width: 80%;
    max-width: 300px;
  }

  .section-subtitle {
    font-size: 16px;
  }
}
</style>